package com.example.androidstart.homepage.viewholder;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.example.androidstart.R;
import com.example.androidstart.homepage.CustomViewHolder;
import com.example.androidstart.homepage.IViewHolderCreator;
import com.example.androidstart.homepage.bean.GoodsInfoBean;
import com.example.androidstart.homepage.item.GoodsItemInfo;

public class GoodsItemViewHolder extends CustomViewHolder<GoodsItemInfo> {

    private GoodsItemViewHolder(@NonNull View itemView) {
        super(itemView);
    }

    public static final IViewHolderCreator<GoodsItemViewHolder> CREATOR = new IViewHolderCreator<GoodsItemViewHolder>() {
        @Override
        public GoodsItemViewHolder createViewHolder(View itemView) {
            return new GoodsItemViewHolder(itemView);
        }

        @Override
        public int getLayoutId() {
            return R.layout.homepage_item_layout;
        }
    };

    @Override
    public void initView() {
        super.initView();
    }

    @Override
    public void onBind(GoodsItemInfo goodsItemInfo) {
        super.onBind(goodsItemInfo);
        TextView textView = itemView.findViewById(R.id.goods_descript);
        GoodsInfoBean goodsInfoBean = goodsItemInfo.getItemInfo();
        textView.setText("商品名称 ：" + goodsInfoBean.getmGoodsName());
        ImageView imageView = itemView.findViewById(R.id.goods_item_img);
        imageView.setImageDrawable(itemView.getContext().getDrawable(goodsInfoBean.getmGoodsRes()));
        TextView price = itemView.findViewById(R.id.goods_price);
        price.setText("价格 : " + goodsInfoBean.getmGoodsPrice());
    }
}
